﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TowerDefence.Entities.States
{
    /// <summary>
    /// Since Entity and Form can contain States, the mechanism
    /// for adding/removing/retreiving them is encapsulated here
    /// </summary>
    public class StateContainer
    {
        private Dictionary<Type, State> states;

        public StateContainer()
        {
            this.states = new Dictionary<Type, State>();
        }

        public void AddState<TState>(TState _state) where TState : State
        {
            this.states[typeof(TState)] = _state;
        }

        public void RemoveState<TState>() where TState : State
        {
            if (GetState<TState>() != null)
            {
                this.states.Remove(typeof(TState));
            }
        }

        public TState GetState<TState>() where TState : State
        {
            State state;
            if (this.states.TryGetValue(typeof(TState), out state))
            {
                return state as TState;
            }
            else return null;
        }
    }
}
